<template>
	<view>
		<view style="background: url(https://static-1310167831.cos.ap-nanjing.myqcloud.com/uploads/20230411/e63bcf73858e37c567847ca55821ddfa.png) no-repeat;background-size: 100%;width: 100%;height: 414rpx;">

		</view>
		<view style="width: 92%;position: absolute;top:10rpx;left: 4%;padding-bottom: 30rpx;">
			<view v-for="(item,index) in list" :key='index' style="overflow: hidden;background-color: #FFFFFF;box-sizing: border-box;padding: 40rpx 30rpx;border-radius: 20rpx;margin-bottom: 20rpx;">
				<view @click="yonghu(item.id)" style="width: 16%;float: left;">
					<image :src="item.avatar" style="width: 88rpx;height: 88rpx;border-radius: 50%;display: block;" mode=""></image>
				</view>
				<view style="width: 36%;float: left;padding: 4rpx 0;">
					<view style="line-height: 40rpx;font-size: 30rpx;color: #000000;">
						{{item.name}}<text style="color: #999999;font-size: 26rpx;margin-left: 10rpx;">{{item.client_position_text}}</text>
					</view>
					<view style="line-height: 40rpx;font-size: 24rpx;color: #999999;" class="yihang">
						<text v-if="is_vip==1">{{item.mobile}}</text>
						<text v-if="is_vip!=1">{{item.mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')}}</text>
					</view>
				</view>
				<view style="width: 48%;float: left;">
					<!-- <view @click="sixin(item.id)" style="width:136rpx;height: 50rpx;line-height: 50rpx;text-align: center;border: 1px solid #1fb0ac;color: #1fb0ac;font-size: 22rpx;border-radius: 25rpx;float: right;margin-top: 15rpx;">
						私信TA
					</view> -->
					<view v-if="index==0" @click="phone(item.mobile)" style="width:136rpx;height: 50rpx;line-height: 50rpx;text-align: center;border: 1px solid #1fb0ac;color: #1fb0ac;font-size: 22rpx;border-radius: 25rpx;float: right;margin-top: 15rpx;margin-right: 16rpx;">
						拨打电话
					</view>
				</view>
			</view>
			<view v-if="kk" style="text-align: center;">
				<image
					src="https://static-1310167831.cos.ap-nanjing.myqcloud.com/uploads/20220329/e86889a9b8fd67d8950e4775d67316c.png"
					style="width: 400rpx;" mode="widthFix"></image>
			</view>
			<u-divider color='#717171' bg-color='#f0f2f8' height='80' border-color='#717171' text="暂无数据"
				v-if="list.length==0"></u-divider>
			<u-divider color='#717171' bg-color='#f0f2f8' height='80' border-color='#717171' text="没有更多了"
				v-if="list.length>0 && enmpy"></u-divider>
		</view>
    <callPhone ref="callPhone" />
	</view>
</template>

<script>
	import isAuditIos from '@/common/isAuditIos.js'
	export default{
		mixins: [isAuditIos],
		data(){
			return{
				page:1,
				list:[],
				enmpy:false,
				kk:false,
				is_vip:2,
				id:''
			}
		},
		onLoad(option) {
			this.id=option.id
			this.wdgz()

		},
		onShow() {
			this.userinfo()
		},

		onReachBottom: function() {
			console.log(222222222)
			if (this.enmpy) {
				return
			} else {
				this.wdgz()
			}
		},
		methods:{
			// 用户信息
			yonghu:function(id){
				uni.navigateTo({
					url:'yhxx?id='+id
				})
			},
			// 私信
			sixin:function(id){
				if(this.is_vip==1){
					this.post('api/chat/msg',{user_id:id},true).then(res=>{
						console.log(res)
						if(res.code==1){
							uni.navigateTo({
								url:'liaotian?roomid='+res.data
							})
						}else{
							uni.showToast({
								title: res.msg,
								icon: "none",
								duration: 1000
							})
						}
					})
				}else if(this.is_vip==0){
					if (this.iosUpAppStore) {
						uni.showModal({
							title: '提示',
							content: '只有会员才可以私信,请前去开通会员！',
							success: function (res1) {
								if (res1.confirm) {
									uni.navigateTo({
										url:'../../../subpages/pages/vip'
									})
								} else if (res1.cancel) {

								}
							}
						});
					} else {
						this.post('api/chat/msg',{user_id:id},true).then(res=>{
							console.log(res)
							if(res.code==1){
								uni.navigateTo({
									url:'liaotian?roomid='+res.data
								})
							}else{
								uni.showToast({
									title: res.msg,
									icon: "none",
									duration: 1000
								})
							}
						})
					}

				}else if(this.is_vip==2){
					if (this.iosUpAppStore) {
						uni.showModal({
							title: '提示',
							content: '只有会员才可以私信,请前去开通会员！',
							success: function (res1) {
								if (res1.confirm) {
									uni.navigateTo({
										url:'../../../subpages/pages/vip'
									})
								} else if (res1.cancel) {

								}
							}
						});
					} else {
						this.post('api/chat/msg',{user_id:id},true).then(res=>{
							console.log(res)
							if(res.code==1){
								uni.navigateTo({
									url:'liaotian?roomid='+res.data
								})
							}else{
								uni.showToast({
									title: res.msg,
									icon: "none",
									duration: 1000
								})
							}
						})
					}
				}


			},
			userinfo: function() {
				this.post('api/client/info', '', true).then(res => {
					console.log(res)
					if (res.code == 1) {
						this.is_vip = res.data.is_vip
					}
				})
			},
			callPhone(phoneNumber) {
				console.log(phoneNumber)
				this.$refs.callPhone.open(phoneNumber)
			},
			phone:function(mobile){
				console.log('%c [ mobile ]-137', 'font-size:13px; background:pink; color:#bf2c9f;', mobile)
				console.log('%c [ this.is_vip ]-139', 'font-size:13px; background:pink; color:#bf2c9f;', this.is_vip)
				if(this.is_vip==1){
					this.callPhone(mobile)
					// uni.makePhoneCall({
					// 	// 手机号
					// 		phoneNumber: mobile,
					// 	// 成功回调
					// 	success: (res) => {
					// 		console.log('调用成功!')
					// 	},
					// 	// 失败回调
					// 	fail: (res) => {
					// 		console.log('调用失败!')
					// 	}
					// });
					// uni.makePhoneCall({
					// 	phoneNumber: mobile //仅为示例
					// });
				}else if(this.is_vip==0){
					if (this.iosUpAppStore) {
						uni.showModal({
							title: '提示',
							content: '只有会员才可以私信,请前去开通会员！',
							success: function (res1) {
								if (res1.confirm) {
									uni.navigateTo({
										url:'../../../subpages/pages/vip'
									})
								} else if (res1.cancel) {

								}
							}
						});
					} else {
						this.post('api/chat/msg',{user_id:id},true).then(res=>{
							console.log(res)
							if(res.code==1){
								uni.navigateTo({
									url:'liaotian?roomid='+res.data
								})
							}else{
								uni.showToast({
									title: res.msg,
									icon: "none",
									duration: 1000
								})
							}
						})
					}
				}else if(this.is_vip==2){
					if (this.iosUpAppStore) {
						uni.showModal({
							title: '提示',
							content: '只有会员才可以私信,请前去开通会员！',
							success: function (res1) {
								if (res1.confirm) {
									uni.navigateTo({
										url:'../../../subpages/pages/vip'
									})
								} else if (res1.cancel) {

								}
							}
						});
					} else {
						this.post('api/chat/msg',{user_id:id},true).then(res=>{
							console.log(res)
							if(res.code==1){
								uni.navigateTo({
									url:'liaotian?roomid='+res.data
								})
							}else{
								uni.showToast({
									title: res.msg,
									icon: "none",
									duration: 1000
								})
							}
						})
					}
				}
			},
			wdgz:function(){
				this.post('api/firm_data/contact',{firm_id:this.id},true).then(res=>{
					console.log(res)
					if(res.code==1){
						if(this.page==1){
							if (res.data== null || res.data.length == 0) {
								this.kk = true
								this.enmpy = true
								return
							} else if (res.data.length < 10) {
								this.enmpy = true
							}
						}else{
							if (res.data== null || res.data.length == 0) {
								this.enmpy = true
								return
							} else if (res.data.length < 10) {
								this.enmpy = true
							}
						}

						this.page++
						let data = res.data
						data.forEach((item) => {
							if (item.client_position_text && item.client_position_text.length) {
								item.client_position_text = item.client_position_text.join(',')
							}
						})
						this.list.push(...data)
						console.log('%c [ this.list ]-253', 'font-size:13px; background:pink; color:#bf2c9f;', this.list)
					}else{
						this.kk = true
						uni.showToast({
							title: res.msg,
							icon: "none",
							duration: 1000
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #F8F8F8!important;
		font-family: Demibold;
	}
</style>
